package com.example.myapplication2

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import kotlinx.android.synthetic.main.activity_broadcast.*

//class BroadcastActivity : AppCompatActivity() {
//    lateinit var timeChangeReceiver: TimeChangeReceiver
//    override fun onCreate(savedInstanceState: Bundle?) {
//        super.onCreate(savedInstanceState)
//        setContentView(R.layout.activity_broadcast)
//        val intentFilter = IntentFilter()
//        intentFilter.addAction("android.intent.action.TIME_TICK")
//        timeChangeReceiver = TimeChangeReceiver()
//        registerReceiver(timeChangeReceiver, intentFilter)
//    }
//    override fun onDestroy() {
//        super.onDestroy()
//        unregisterReceiver(timeChangeReceiver)
//    }
//    inner class TimeChangeReceiver : BroadcastReceiver() {
//        override fun onReceive(context: Context, intent: Intent) {
//            Toast.makeText(context, "Time has changed", Toast.LENGTH_SHORT).show()
//        }
//    }
//}
class BroadcastActivity  : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_broadcast)
        button.setOnClickListener {
            val intent = Intent("com.example.broadcasttest.MY_BROADCAST")
            intent.setPackage(packageName)
            //sendBroadcast(intent)
            sendOrderedBroadcast(intent, null)
        }

    }

}